/**
 * @version 1.8
 * @Author Djx_hmbb
 * @Date 2023/8/9 17:06
 * @注释:等待线程
 * 阻塞:主线程和t同时运行,若主线程已经到达下一条命令,但是t还没有,则main等待t
 */
public class ThreadDemo9 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            for (int i =0;i<3;++i) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        try {
            t.join();//等待线程死亡
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("---join");
        try {
            t.join();
//            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("join----");
    }
}
